// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.web.converter;

import java.util.Map;
import net.taviscaron.drivenotes.shared.model.entity.Note;
import net.taviscaron.drivenotes.web.util.ParamUtils;

/**
 * Note converter
 * @author Andrei Senchuk
 */
public class NoteConverter extends FormConverter<Note> {
    @Override
    public Note convert(Map params, String prefix) throws InvalidFormException {
        try {
            Note note = new Note();
            note.setId(ParamUtils.parseLongParam(params, "id", prefix));
            note.setName(ParamUtils.parseStringParam(params, "name", prefix));
            note.setNote(ParamUtils.parseStringParam(params, "note", prefix));
            return note;
        } catch (IllegalArgumentException e) {
            throw new InvalidFormException();
        }
    }
}
